﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Main.src.display
{

    /// <summary>
    /// Permite desenhar uma imagem na tela
    /// </summary>
    public sealed class Sprite : DisplayObject
    {

        public Texture2D Texture = null; // Textura

        /// <summary>
        /// Construtor
        /// </summary>
        /// <param name="texture">Textura</param>
        public Sprite(Texture2D texture = null)
        {
            if (texture != null)
                Texture = texture;
        }

        /// <summary>
        /// Desenha na tela
        /// </summary>
        /// <param name="spriteBatch">SpriteBatch do Main</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            if ((Invisible) || (Texture == null))
                return;
            spriteBatch.Draw(Texture, Position, SourceRectangle, Color, Rotation, Origin, Scale, Effects, LayerDepth);
        }

        /// <summary>
        /// Destrutor
        /// </summary>
        public override void Dispose()
        {
            base.Dispose();
            Texture = null;
        }

        /// <summary>
        /// Pega o tamanho da textura
        /// </summary>
        public Vector2 Size
        {
            get
            {
                if (Texture == null)
                    return Vector2.Zero;
                return new Vector2(Texture.Width, Texture.Height);
            }
        }

        /// <summary>
        /// Pega a largura da textura
        /// </summary>
        public int Width
        {
            get
            {
                if (Texture == null)
                    return 0;
                return Texture.Width;
            }
        }

        /// <summary>
        /// Pega a altura da textura
        /// </summary>
        public int Height
        {
            get
            {
                if (Texture == null)
                    return 0;
                return Texture.Height;
            }
        }

    }

}